<?php
namespace Common\Model;

class ConfigModel extends IModel
{
    protected $_validate = [
        ['name', 'require', '请填写配置名', self::EXISTS_VALIDATE],
        ['name', '', '该配置名已存在', self::EXISTS_VALIDATE , 'unique'],
    ];

    protected $_auto = [
        ['items', 'serialize', self::MODEL_BOTH, 'function'],
        ['created_at', 'time', self::MODEL_INSERT, 'function'],
    ];

    protected function _after_find(&$record, $options)
    {
        if (isset($record['items'])) $record['items'] = unserialize($record['items']);
    }

    protected function _after_select(&$records, $options)
    {
        foreach ($records as &$record) {
            $this->_after_find($record, $options);
        }
    }
   
    // protected function _after_update(&$data, $options) {
    //     S(C('SETTING_CACHE_NAME'), null);
    // }

    // protected function _after_insert(&$data, $options) {
    //     S(C('SETTING_CACHE_NAME'), null);
    // }
}
